#include "checkdialog.h"
#include "ui_checkdialog.h"
#include<QCloseEvent>
#include<QSqlQuery>
#include<QSqlError>
#include<QMessageBox>

CheckDialog::CheckDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CheckDialog)
{
    ui->setupUi(this);
    setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint);
}

CheckDialog::~CheckDialog()
{
    delete ui;
}

void CheckDialog::on_pushButton_clicked()
{
    checkWorkNumber=ui->lineEdit->text().trimmed();
    if(checkWorkNumber==""){
        ui->label_5->setText("带*号字段不能为空");
    }else{
        if(isExist(checkWorkNumber)){
            cycle=ui->spinBox->value();
            isSkipRest=(ui->checkBox->checkState()==Qt::Checked);
            close();
        }else{
            ui->label_5->setText("工号不存在");
        }
    }
}

bool CheckDialog::isExist(QString wn){
    QSqlQuery sqlQuery;
    sqlQuery.exec(QString("select account from oper_role_user where account=%1").arg(wn));
    if(!sqlQuery.lastError().isValid()){
        if(sqlQuery.next()){
            return true;
        }else{
            return false;
        }
    }else{
//        QMessageBox::critical(this,"错误","数据库连接失败！\n\n"+sqlQuery.lastError().text());
        return false;
    }
}


//void CheckDialog::on_pushButton_clicked()
//{
//    if(ui->lineEdit->text().trimmed()==""){
//        ui->label_5->setText("带*号字段不能为空");
//        finishFlag=false;
//    }else{
//        finishFlag=true;
//        closeFlag=true;
//        close();
//    }
//}

//void CheckDialog::closeEvent(QCloseEvent *event){
//    if(!closeFlag){
//        finishFlag=false;
//    }
//    closeFlag=false;
//    event->accept();
//}

//void CheckDialog::on_lineEdit_textChanged(const QString &arg1)
//{
//    if(arg1.trimmed()==""){
//        finishFlag=false;
//    }
//}
